/**
 * FriendAttentionController.java
 */
package com.tobeface.sns.interfaces;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kissme.core.orm.Page;
import com.tobeface.sns.application.pal.FriendRelationService;
import com.tobeface.sns.domain.User;
import com.tobeface.sns.interfaces.exception.BindingException;
import com.tobeface.sns.interfaces.util.UserUtil;

/**
 * @author Dylan
 * @time 2012-8-8
 */
@Controller
@RequestMapping(value = "/friend-attention")
public class FriendAttentionController {

	@Resource
	private FriendRelationService friendRelationService;

	@ResponseBody
	@RequestMapping(value = "/attention", method = RequestMethod.POST)
	public void attentionFriend(User friend, BindingResult result) {
		if (result.hasErrors()) {
			throw new BindingException();
		}
		User self = UserUtil.getCurrentLoginUser();
		friendRelationService.attentionFriend(self, friend);
	}

	@ResponseBody
	@RequestMapping(value = "/cacel-attention", method = RequestMethod.POST)
	public void cancelAttention(User friend, BindingResult result) {
		if (result.hasErrors()) {
			throw new BindingException();
		}
		User self = UserUtil.getCurrentLoginUser();
		friendRelationService.cancelAttention(self, friend);
	}

	@RequestMapping(value = "/attention-who", method = RequestMethod.POST)
	public String attentionWho(Page<User> page, Model model) {
		User self = UserUtil.getCurrentLoginUser();
		page = friendRelationService.attentionWho(page, self);
		model.addAttribute(page);
		return "";
	}

	@RequestMapping(value = "/who-attention", method = RequestMethod.POST)
	public String whoAttention(Page<User> page, Model model) {
		User self = UserUtil.getCurrentLoginUser();
		page = friendRelationService.whoAttention(page, self);
		model.addAttribute(page);
		return "";
	}
}
